package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.presentation.controller.admin.devtypes;

import java.util.ArrayList;
import java.util.List;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.Alarm;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.DeviceType;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.Field;

public class AlarmBean {

	private Alarm alarm;

	public AlarmBean(Alarm alarm) {
		this.alarm = alarm;
	}

	public String getName() {
		return alarm.getName();
	}

	public void setName(String name) {
		alarm.setName(name);
	}

	public Integer getField() {
		return alarm.getField().hashCode();
	}

	public void setField(Integer hash) {
		DeviceType dev = alarm.getDeviceType();
		for (Field field : dev.getFields()) {
			if(field.hashCode() == hash){
				alarm.setField(field);
				break;
			}
		}
	}

	public Alarm.Operator getMethod() {
		return alarm.getOperator();
	}

	public void setMethod(Alarm.Operator method) {
		alarm.setOperator(method);
	}

	public Integer getValue() {
		return alarm.getThreshold();
	}

	public void setValue(Integer value) {
		alarm.setThreshold(value);
	}

	public static List<AlarmBean> wrap(List<Alarm> alarms) {
		List<AlarmBean> ret = new ArrayList<AlarmBean>();
		for (Alarm alarm : alarms) {
			ret.add(new AlarmBean(alarm));
		}
		return ret;
	}

	public Alarm getAlarm() {
		return alarm;
	}
}
